﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using UIWindow.DeviceCommunications;
using UIWindow.Domains;
using UIWindow.GlobalParameters;
using UIWindow.Helper;
using UIWindow.Lucifer;

namespace UIWindow.Services
{
    public abstract class TaskEventBase<T> where T : IDataContext, new()
    {
        private readonly log4net.ILog _log = log4net.LogManager.GetLogger("message");
        public virtual Task Handle(T context)
        {
            var comm = Bootstrapper.GetContainer().ResolveSingleton<DeviceGlobal>().DeviceList.FirstOrDefault(x => x.Types == Enums.DeviceType.注液机);
            bool bools = false;
            string str = context.Types.ToString();
            for (int i = 0; i < 2; i++)
            {
                if (!bools) bools = comm.Comm.Write(new Models.S7NET.S7ParamModel()
                {
                    Address = context.AddressSignal,
                    Value = new byte[] { 0x00, 0x00 }
                });//信号地址清零

                if (i == 1 || bools) break;
            }
            if (!bools) _log.Error($"清零{str}信号失败\r\n");
            _log.Info($"{str}处理完成\r\n");
            TaskManager.RemoveTask(context);
            return Task.CompletedTask;
        }
    }
}
